import {
	getUserInfo,
	saveUserInfo
} from "@/api/members";
import {
	mpAutoLogin
} from "@/api/connect.js";

import {
	autoLogin

} from "@/api/mbti"


import storage from "@/utils/storage.js";

import store from "@/store/index.js";
import config from "@/config/config";

export default function silentLogin(loginPayload = {}) {
	// console.log("调用静默登录函数");
	let provider = "weixin" // 运营商 默认是微信
	let code = "" //登录code码

	// code = 0f1MBsFa18QAjI0InZFa1RptqF1MBsF9
	return new Promise(async (resolve, reject) => {
		code = await handleGetLoginCode()

		let payload = {
			code: code,
		}
		autoLogin(payload).then(res => {
			// 存储token
			// storage.setAccessToken(apiRes.data.result.accessToken);
			// storage.setRefreshToken(apiRes.data.result
			// 	.refreshToken);


			// 登录成功获取用户信息







		})






	})

}


function handleGetLoginCode() {
	return new Promise((resolve, reject) => {
		uni.login({
			success: (res) => {
				if (res.errMsg === "login:ok") {
					// console.log("成功", res);
					resolve(res.code)
				}
			},
			fail: (err) => {
				uni.showToast({
					title: "登录失败",
					icon: 'none'
				})
			}

		})
	})
}

function handleGetLoginCodePlugin() {
	return new Promise((resolve, reject) => {
		uni.login({
			success: (res) => {
				if (res.errMsg === "login:ok") {
					// console.log("成功", res);
					resolve(res.code)
				}
			},
			fail: (err) => {
				uni.showToast({
					title: "登录失败",
					icon: 'none'
				})
			}

		})
	})
}
export {
	handleGetLoginCodePlugin
}